//
//  ToolbarHomeWebsiteView.m
//  BaoVn
//
//  Created by Le Anh Tai on 11/16/14.
//  Copyright (c) 2014 Le Anh Tai. All rights reserved.
//

#import "ToolbarHomeWebsiteView.h"

@implementation ToolbarHomeWebsiteView

- (instancetype)init
{
    if (self = [super init])
    {
        _badgeButton = [[BadgeButton alloc] init];
        [_badgeButton addTarget:self action:@selector(badgetButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_badgeButton];
        
        _menuButton = [[UIButton alloc] init];
        [_menuButton setImage:[UIImage imageNamed:@"icon_menu.png"] forState:UIControlStateNormal];
        [_menuButton addTarget:self action:@selector(menuButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_menuButton];
    }
    
    return self;
}

- (void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
    
    NSInteger size = self.height;
    
    _menuButton.frame = RECT(self.width - size, 0, size, size);
    _badgeButton.frame = RECT(_menuButton.left - size - 4, 0, size, size);
}

- (void)badgetButtonPressed
{
    if ([_delegate respondsToSelector:@selector(toolbarHomeWebsiteDidPressBadgeButton:)])
    {
        [_delegate toolbarHomeWebsiteDidPressBadgeButton:self];
    }
}

- (void)menuButtonPressed
{
    if ([_delegate respondsToSelector:@selector(toolbarHomeWebsiteDidPressMenuButton:)])
    {
        [_delegate toolbarHomeWebsiteDidPressMenuButton:self];
    }
}

@end
